<?php echo previous_link($section,$action,$go,$modal_window); 
if ($msg != "default") echo $msg_output; 

if (($action == "edit") || ($action == "confirm")) {
$query_edit = "SELECT * FROM learning_outcomes WHERE id='$id'";
$edit = mysql_query($query_edit, $connection) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
}

$query_cd = "SELECT * FROM project_deliverable WHERE cid='$cid' ORDER BY mid,del_num ASC";
$cd = mysql_query($query_cd, $connection) or die(mysql_error());
$row_cd = mysql_fetch_assoc($cd);

?>
<?php if ($action != "confirm") { 

if ($modal_window == "false") {
		if (!lo_deliverable_match($cid)) { echo "<div class='info'>Each deliverable now has an associated learning outcome. If you are finished,"; if ($go == "overview") echo " <a href='index.php?section=view_proposal&cid=".$cid."'>go back to the course overview</a>."; else echo  " <a href='index.php?section=proposal_reveiw&cid=".$cid."&msg=1'>review your completed proposal</a>.";  echo "</div>"; 
		} 
	}
?>
<div class="stacked"><span class="icon"><img src="images/page_add.png" border="0" align="absmiddle" /></span><a href="index.php?section=proj_deliv&amp;action=add&amp;go=<?php echo $go; ?>&amp;cid=<?php echo $cid; ?>&amp;modal_window=<?php echo $modal_window; ?>">Add Another Project Deliverable?</a></div>
<p>Based upon the project deliverables, create the associated course learning outcomes for <?php echo $row_courses['jiu_course_id']." - ".$row_courses['name']; ?>.</p>
<?php } if ($action == "view") { ?>
<table class="dataTable">
<tr>
	<th width="20%">Weekly Project Deliverable</th>
    <th width="28%">What Students Need to Know</th>
    <th width="28%">Associated Learning Outcome(s)</th>
    <th>Actions</th>
</tr>
<?php 
// Make a MySQL Connection
// Get all 
$query_pd = "SELECT * FROM project_deliverable WHERE cid='$cid'";
$pd = mysql_query($query_pd, $connection) or die(mysql_error());
$row_pd = mysql_fetch_assoc($pd);
$totalRows_pd = mysql_num_rows($pd);
if ($totalRows_pd > 0) {
	do { $c[] = $row_pd['mid']; } while($row_pd = mysql_fetch_assoc($pd));
	sort ($c);
		foreach (array_unique($c) as $value) {
				// Was NOT returning the first row for some reason - MUST use the do...while loop to build the arrays.
				$query_pd_num = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' ORDER BY vid ", $cid, $value);
				$pd_num = mysql_query($query_pd_num, $connection) or die(mysql_error());
				$row_pd_num = mysql_fetch_assoc($pd_num);
				$totalRows_pd_num = mysql_num_rows($pd_num);

			    do { $d[] = $row_pd_num['del_num']; } while ($row_pd_num = mysql_fetch_assoc($pd_num));
				
				sort($d);
				foreach (array_unique($d) as $value1) {
										
						$query_pd_loop = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' AND del_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $value, $value1);
						$pd_loop = mysql_query($query_pd_loop, $connection) or die(mysql_error());
						$row_pd_loop = mysql_fetch_assoc($pd_loop);
						$totalRows_pd_loop = mysql_num_rows($pd_loop);	
						
						if ($totalRows_pd_loop > 0) {
							echo "<tr style='background-color: ".$color."'>\n";
							echo "<td>
								<table class='dataTableCompact'>
        							<tr>
        								<td>Deliverable ".$row_pd_loop['del_num'].": ".$row_pd_loop['pd_name']."</td>
        							</tr>
									<tr>
        								<td>Applies to: Module ".$row_pd_loop['mid']."</td>
       								</tr>
        						</table>";
							echo "</td>\n";
							echo "<td class='data'>".$row_pd_loop['pd_desc2']."</td>\n";
							echo "<td class='data'>";
							
							$query_lo = sprintf("SELECT * FROM learning_outcomes WHERE cid='%s' AND del_num='%s' ORDER BY id", $cid, $value1);
							$lo = mysql_query($query_lo, $connection) or die(mysql_error());
							$row_lo = mysql_fetch_assoc($lo);
							$totalRows_lo = mysql_num_rows($lo);
							if (lo_check($cid,$value1)) {
								do { 
								 echo "\t<div class='stacked'>".$row_lo['lo_text']." </div><div class='stacked'><span class='icon'><img src='images/page_edit.png' align='absmiddle' border='0'></span><a href='index.php?section=clo&action=edit&go=no&cid=".$cid."&mid=".$value."&del_num=".$value1."&id=".$row_lo['id']."&amp;modal_window=".$modal_window."'>Edit</a> This Learning Outcome</div><div class='stacked'><span class='icon'><img src='images/bin_closed.png' align='absmiddle' border='0'></span><a href=\"javascript:confirmation('includes/process.inc.php?dbTable=learning_outcomes&action=delete','id','".$row_lo['id']."','Are you sure you want to delete this Learning Outcome?');\">Delete</a> This Learning Outcome</div>\n";  
								 } while ($row_lo = mysql_fetch_assoc($lo));
							
							} else { $lo_check = "false"; echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>There are no learning outcomes associated with this deliverable."; }
							echo "</td>";
							echo "<td class='data'>
							<div class='stacked'><span class='icon'><img src='images/page_add.png' align='absmiddle' border='0'></span><a href='index.php?section=clo&action=add&cid=".$cid."&mid=".$row_pd_loop['mid']."&del_num=".$row_pd_loop['del_num']."&amp;modal_window=".$modal_window."'>Add a Learning Outcome</a> for This Deliverable</div>
        					<div class='stacked'><span class='icon'><img src='images/page_edit.png' align='absmiddle' border='0'></span><a href='index.php?section=proj_deliv&action=edit&cid=".$cid."&vid=".$row_pd_loop['vid']."&id=".$row_pd_loop['id']."&amp;modal_window=".$modal_window."'>Edit</a> This Deliverable</div>
							</td>";
							echo "</tr>\n";
							if ($color == $color1) { $color = $color2; } else { $color = $color1; }
							}
						}
				  unset($d);
				}
			unset($c);
echo "</table>";
	}
}
if (($action == "add") || ($action == "edit")) {

$query_pd = "SELECT * FROM project_deliverable WHERE cid='$cid' AND mid='$mid' AND del_num='$del_num'";
$pd = mysql_query($query_pd, $connection) or die(mysql_error());
$row_pd = mysql_fetch_assoc($pd);
$totalRows_pd = mysql_num_rows($pd);
//echo $query_pd;
?>
<?php if ($action == "add") { ?>
<h2><?php echo "Module ".$row_pd['mid'].", Deliverable ".$row_pd['del_num'].": ".$row_pd['pd_name']; ?></h2>
<div class="stacked">
<span class="icon"><img src="images/disk.png" border="0" align="absmiddle" /></span><input id="Submit" name="Submit" type="submit" class="save_progress_form" value="<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>">
</div>
<table class="dataTable">
<tr>
	<th width="10%">Activity</th>
    <th>Description</th>
    <th width="40%">Craft the Learning Outcome</th>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Weekly Project Deliverable</td>
    <td class="data"><?php echo $row_pd['pd_desc1']; ?></td>
    <td class="data" rowspan="5" style="border-left: 1px solid #cccccc;">
    <p>Upon successful completion of this course, each student will be able to:</p>
    <textarea id="lo_text" name="lo_text" type="text" cols="60" rows="7" class="mceNoEditor"><?php if ($action == "edit") echo $row_edit['lo_text']; ?></textarea>
    <p class="help_text">To begin the outcome, use action words such as:
    <ul>
    	<li>analyze</li>
        <li>identify</li>
        <li>compose</li>
        <li>synthesize</li>
        <li>select</li>
        <li>justify</li>
        <li>formulate</li>
        <li>apply</li>
        <li>demonstrate</li>
    </ul>
    </p>
    </td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">  
    <td class="dataLabel">What Students Need to Know</td>
    <td class="data"><?php echo $row_pd['pd_desc2']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td class="dataLabel">Information Covered in Themes</td>
    <td class="data"><?php echo $row_pd['pd_desc3']; ?></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
    <td class="dataLabel">Information Covered in Readings</td>
    <td class="data"><?php echo $row_pd['pd_desc4']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td class="dataLabel">Topics Discussed in Forum</td>
    <td class="data"><?php echo $row_pd['pd_desc5']; ?></td>
</tr>
</table>
<div class="stacked">
<span class="icon"><img src="images/disk.png" border="0" align="absmiddle" /></span><input id="Submit" name="Submit" type="submit" class="save_progress_form" value="<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>">
</div>
<?php } ?>
<?php if (($action == "edit") && ($msg != "5")) { 
$query_pd = "SELECT * FROM project_deliverable WHERE cid='$cid'";
$pd = mysql_query($query_pd, $connection) or die(mysql_error());
$row_pd = mysql_fetch_assoc($pd);
$totalRows_pd = mysql_num_rows($pd);
?>
<div class="stacked">
<span class="icon"><img src="images/disk.png" border="0" align="absmiddle" /></span><input id="Submit" name="Submit" type="submit" class="save_progress_form" value="<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>">
</div>
<table class="dataTable">
<tr>
	<th width="50%">Applies To</th>
    <th>Learning Outcome</th>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td>
<?php 
    if ($totalRows_pd > 0) {
	// echo "<select name='del_num'>";
	do { $c[] = $row_pd['mid']; } while($row_pd = mysql_fetch_assoc($pd));
		foreach (array_unique($c) as $value) {
				// Was NOT returning the first row for some reason - MUST use the do...while loop to build the arrays.
				$query_pd_num = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' ORDER BY vid ", $cid, $value);
				$pd_num = mysql_query($query_pd_num, $connection) or die(mysql_error());
				$row_pd_num = mysql_fetch_assoc($pd_num);
				$totalRows_pd_num = mysql_num_rows($pd_num);
			    do { $d[] = $row_pd_num['del_num']; } while ($row_pd_num = mysql_fetch_assoc($pd_num));
				sort($d);
				foreach (array_unique($d) as $value1) {
										
						$query_pd_loop = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' AND del_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $value, $value1);
						$pd_loop = mysql_query($query_pd_loop, $connection) or die(mysql_error());
						$row_pd_loop = mysql_fetch_assoc($pd_loop);
						$totalRows_pd_loop = mysql_num_rows($pd_loop);	
						if ($totalRows_pd_loop > 0) { echo "<div><input type='radio' name='del_num' value='".$row_pd_loop['del_num']."'"; if ($row_pd_loop['del_num'] == $row_edit['del_num']) echo "CHECKED"; echo "> Deliverable ".$row_pd_loop['del_num'].": ".$row_pd_loop['pd_name']."</div>";	}
				}
		}
	}
	 echo "</select>";
	?>
    </td>
    <td class="data">
    <p>Upon successful completion of this course, each student will be able to:</p>
    <textarea id="lo_text" name="lo_text" type="text" cols="60" rows="7" class="mceNoEditor"><?php if ($action == "edit") echo $row_edit['lo_text']; ?></textarea>
    <p class="help_text">To begin the outcome, use action words such as:
    <ul>
    	<li>analyze</li>
        <li>identify</li>
        <li>compose</li>
        <li>synthesize</li>
        <li>select</li>
        <li>justify</li>
        <li>formulate</li>
        <li>apply</li>
        <li>demonstrate</li>
    </ul>
    </p>
    </td>
</tr>
</table>
<div class="stacked">
<span class="icon"><img src="images/disk.png" border="0" align="absmiddle" /></span><input id="Submit" name="Submit" type="submit" class="save_progress_form" value="<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>">
</div>
<?php } ?>
<?php if ($action == "add") { ?><input type="hidden" name="del_num" value="<?php echo $del_num; ?>" /><?php } ?>
<?php if ($action == "add") { ?><input type="hidden" name="mid" value="<?php echo $mid; ?>" /><?php } ?>
<?php if ($action == "edit") { ?><input type="hidden" name="mid" value="<?php echo $row_edit['mid']; ?>" /><?php } ?>
<input type="hidden" name="cid" value="<?php echo $cid; ?>" />

<?php } 
if ($action == "confirm") {
?>
<h2>Confirm</h2>
<div class="stacked">Is the course learning outcome acceptable?</div>
<div class="stacked"><span class="icon"><img src="images/tick.png" border="0" align="absmiddle" /></span><a href="index.php?section=clo&amp;action=view&amp;cid=<?php echo $cid; ?>&amp;modal_window=<?php echo $modal_window; ?>">Yes</a></div>
<div class="stacked"><span class="icon"><img src="images/exclamation.png" border="0" align="absmiddle" /></span><a href="index.php?section=clo&amp;action=edit&amp;go=no&amp;cid=<?php echo $cid; ?>&amp;mid=<?php echo $mid; ?>&amp;del_num=<?php echo $del_num; ?>&amp;id=<?php echo $row_edit['id']; ?>&amp;modal_window=<?php echo $modal_window; ?>">No, further editing is required</a></div>
<table class="dataTable">
<tr>
	<th>Upon successful completion of this course, each student will be able to:</th>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td><?php echo $row_edit['lo_text']; ?></td>
</tr>
</table>
<?php } ?>